<template>
  <a-card :bordered="false">
    <div class="table-operator">
      <a-button icon="plus" @click="$refs.AddOrUpdate.init('','add')" type="primary">新建</a-button>
    </div>
    <v-table
      bordered
      ref="table"
      :data="loadData"
      :columns="tableColumns"
    >
      <span slot="action" slot-scope="{row,text}">
        <span>
          <a href="javascript:;" @click="edit(row)">编辑</a>
          <a-divider type="vertical" />
        </span>
        <span>
          <a href="javascript:;" @click="design(row)">设计表单</a>
          <a-divider type="vertical" />
        </span>
        <a-dropdown>
          <a class="ant-dropdown-link"> 更多<a-icon type="down" /> </a>
          <a-menu slot="overlay">
            <a-menu-item key="0">
              <a-popconfirm title="是否删除表单" @confirm="deleteItem(row)" okText="是" cancelText="否">
                <a-icon slot="icon" type="question-circle-o" style="color: red" />
                <a href="javascript:;">删除</a>
              </a-popconfirm>
            </a-menu-item>
            <a-menu-item key="1">
              <span>
                <a href="javascript:;" @click="formData(record)">表单数据</a>
                <a-divider type="vertical" />
              </span>
            </a-menu-item>
          </a-menu>
        </a-dropdown>
      </span>
    </v-table>
    <add-or-update
      ref="AddOrUpdate"
      @ok="queryPage"
    />
  </a-card>

</template>

<script>
import { TableMixin } from '@/mixins/TableMixin'
import { fetchList, delObj } from '@/api/dynamicForm/design'
import AddOrUpdate from './AddOrUpdate'
import { tableColumns, queryObj } from './design'
export default {
  name: 'Index',
  mixins: [TableMixin],
  components: {
    AddOrUpdate
  },
  data () {
    return {
      queryObj,
      tableColumns,
      loadData: parameter => {
        return fetchList(
          Object.assign(parameter, this.queryParam)
        ).then(res => {
          return res.data
        })
      }
    }
  },
  methods: {
    edit (record) {
      this.$refs.AddOrUpdate.init(record.id, 'edit')
    },
    deleteItem (record) {
      delObj(record.id).then(res => {
        this.$message.info('删除成功')
        this.queryPage()
      })
    },
    design (record) {
      this.$router.push({
        name: 'dynamicForm',
        params: {
          id: record.id
        }
      })
    },
    formData (record) {
      this.$router.push({
        name: 'formData',
        params: {
          formCode: record.code
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
